import 'package:flutter/material.dart';
import 'package:hrcapp/utils/theme_colors.dart';

class HRCAuthenticationEvaluationScreen extends StatefulWidget {
  const HRCAuthenticationEvaluationScreen({Key? key}) : super(key: key);

  @override
  State<HRCAuthenticationEvaluationScreen> createState() => _HRCAuthenticationEvaluationScreenState();
}

class _HRCAuthenticationEvaluationScreenState extends State<HRCAuthenticationEvaluationScreen> {
  // 资产信息数据
  final String assetName = '清代苏绣花鸟图轴';
  final String assetType = '苏绣';
  final String uploadDate = '2023-05-15';
  final String submitter = '张三';

  // 评估信息数据
  final String evaluationAgency = '苏州非遗保护中心';
  final String evaluationExpert = '王丽 (苏绣国家级传承人)';
  final String evaluationStatus = '待评估';
  final String estimatedCompletionTime = '3个工作日内';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ThemeColors.background,
      appBar: AppBar(
        title: const Text('非遗资产认证评估'),
        backgroundColor: Colors.white,
        elevation: 1,
        leading: IconButton(
          icon: const Icon(Icons.arrow_back, color: Colors.black),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 24),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // 流程指示器
            _buildProcessIndicator(),
            const SizedBox(height: 24),

            // 资产基本信息卡片
            _buildAssetInfoCard(),
            const SizedBox(height: 24),

            // 认证评估信息卡片
            _buildEvaluationInfoCard(),
            const SizedBox(height: 40),

            // 底部操作按钮
            SizedBox(
              width: double.infinity,
              child: ElevatedButton(
                onPressed: () {
                  // 查看评估标准按钮点击事件
                  _viewEvaluationCriteria();
                },
                style: ElevatedButton.styleFrom(
                  backgroundColor: ThemeColors.primary,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(25),
                  ),
                  padding: const EdgeInsets.symmetric(vertical: 16),
                  elevation: 4,
                ),
                child: const Text(
                  '查看评估标准',
                  style: TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                    color: Colors.white,
                  ),
                ),
              ),
            ),
            const SizedBox(height: 16),
            
            // 提交功能按钮
            SizedBox(
              width: double.infinity,
              child: ElevatedButton(
                onPressed: () {
                  // 提交功能按钮点击事件
                  _submitEvaluation();
                },
                style: ElevatedButton.styleFrom(
                  backgroundColor: ThemeColors.secondary,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(25),
                  ),
                  padding: const EdgeInsets.symmetric(vertical: 16),
                  elevation: 4,
                ),
                child: const Text(
                  '提交认证评估',
                  style: TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                    color: Colors.white,
                  ),
                ),
              ),
            ),
            const SizedBox(height: 32),
          ],
        ),
      ),
    );
  }

  // 构建流程指示器
  Widget _buildProcessIndicator() {
    return Container(
      margin: const EdgeInsets.only(bottom: 8),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              _buildStepIndicator('资产上传', false, 1),
              _buildStepConnector(true),
              _buildStepIndicator('认证评估', true, 2),
              _buildStepConnector(false),
              _buildStepIndicator('价值锚定', false, 3),
              _buildStepConnector(false),
              _buildStepIndicator('生成通证', false, 4),
              _buildStepConnector(false),
              _buildStepIndicator('上链完成', false, 5),
            ],
          ),
        ],
      ),
    );
  }

  // 构建步骤指示器
  Widget _buildStepIndicator(String label, bool isActive, int stepNumber) {
    return Column(
      children:
      [
        Container(
          width: 30,
          height: 30,
          decoration: BoxDecoration(
            shape: BoxShape.circle,
            color: isActive ? ThemeColors.primary : const Color(0xFFE5E6EB),
          ),
          child: Center(
            child: Text(
              '$stepNumber',
              style: const TextStyle(
                fontSize: 14,
                fontWeight: FontWeight.bold,
                color: Colors.white,
              ),
            ),
          ),
        ),
        const SizedBox(height: 8),
        SizedBox(
          width: 60,
          child: Text(
            label,
            textAlign: TextAlign.center,
            style: TextStyle(
              fontSize: 12,
              color: isActive ? ThemeColors.primary : const Color(0xFF86909C),
            ),
          ),
        ),
      ],
    );
  }

  // 构建步骤连接器
  Widget _buildStepConnector(bool isActive) {
    return Expanded(
      child:
      Container(
        height: 2,
        margin: const EdgeInsets.symmetric(horizontal: 4),
        color: isActive ? ThemeColors.primary : const Color(0xFFE5E6EB),
      ),
    );
  }

  // 构建资产信息卡片
  Widget _buildAssetInfoCard() {
    return Container(
      padding: const EdgeInsets.all(30),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
      ),
      child:
      Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children:
        [
          const Text(
            '资产基本信息',
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.bold,
              color: Colors.black,
            ),
          ),
          const SizedBox(height: 15),
          Row(
            children:
            [
              // 资产图片占位符
              Container(
                width: 100,
                height: 100,
                decoration: BoxDecoration(
                  color: const Color(0xFFF5F5F5),
                  borderRadius: BorderRadius.circular(8),
                ),
                child: Center(
                  child: Icon(
                    Icons.image, 
                    size: 40,
                    color: ThemeColors.primary,
                  ),
                ),
              ),
              const SizedBox(width: 20),
              // 资产信息
              Expanded(
                child:
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children:
                  [
                    Text(
                      assetName,
                      style: const TextStyle(
                        fontSize: 16,
                        fontWeight: FontWeight.bold,
                        color: Colors.black,
                      ),
                    ),
                    const SizedBox(height: 5),
                    Text('资产类型：$assetType'),
                    const SizedBox(height: 5),
                    Text('上传时间：$uploadDate'),
                    const SizedBox(height: 5),
                    Text('提交人：$submitter'),
                  ],
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

  // 构建认证评估信息卡片
  Widget _buildEvaluationInfoCard() {
    return Container(
      padding: const EdgeInsets.all(30),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
      ),
      child:
      Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children:
        [
          const Text(
            '认证评估信息',
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.bold,
              color: Colors.black,
            ),
          ),
          const SizedBox(height: 20),

          // 评估机构
          _buildInfoRow('评估机构', evaluationAgency),
          const SizedBox(height: 25),

          // 评估专家
          _buildInfoRow('评估专家', evaluationExpert),
          const SizedBox(height: 25),

          // 评估状态和预计完成时间
          Row(
            children:
            [
              Expanded(
                child:
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children:
                  [
                    const Text('评估状态'),
                    const SizedBox(height: 10),
                    Container(
                      width: 100,
                      height: 40,
                      decoration: BoxDecoration(
                        color: const Color(0xFFFFF7E6),
                        borderRadius: BorderRadius.circular(6),
                      ),
                      child: Center(
                        child:
                        Text(
                          evaluationStatus,
                          style: const TextStyle(
                            fontSize: 14,
                            fontWeight: FontWeight.bold,
                            color: Color(0xFFFAAD14),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              const SizedBox(width: 20),
              Expanded(
                child:
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children:
                  [
                    const Text('预计完成时间'),
                    const SizedBox(height: 10),
                    Container(
                      height: 40,
                      decoration: BoxDecoration(
                        color: const Color(0xFFF0F2F5),
                        borderRadius: BorderRadius.circular(6),
                      ),
                      child: Center(
                        child:
                        Text(estimatedCompletionTime),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

  // 构建信息行
  Widget _buildInfoRow(String label, String value) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children:
      [
        Text(label),
        const SizedBox(height: 10),
        Container(
          width: double.infinity,
          height: 40,
          decoration: BoxDecoration(
            color: const Color(0xFFF0F2F5),
            borderRadius: BorderRadius.circular(6),
          ),
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 20),
            child:
            Align(
              alignment: Alignment.centerLeft,
              child:
              Text(value),
            ),
          ),
        ),
      ],
    );
  }

  // 查看评估标准
  void _viewEvaluationCriteria() {
    // 跳转到评估标准页面
    Navigator.pushNamed(context, '/evaluationCriteria');
  }

  // 提交认证评估
  void _submitEvaluation() {
    // 提交认证评估的逻辑
    ScaffoldMessenger.of(context).showSnackBar(
      const SnackBar(content: Text('认证评估已提交')),
    );
    
    // 跳转到价值锚定页面
    Navigator.pushNamed(context, '/assetAnchoring');
  }
}